-
Notifications
You must be signed in to change notification settings - Fork 4
Speed up builds with less sleeps steps #376
Conversation
vars/getVaultSecret.groovy
Outdated
| sleep randomNumber(min: 5, max: 10) | ||
| def token = getVaultToken(env.VAULT_ADDR, env.VAULT_ROLE_ID, env.VAULT_SECRET_ID) | ||
| props = getVaultSecretObject(env.VAULT_ADDR, secret, token) | ||
| retry(3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increased the number of retries a shorter sleep
vars/git.groovy
Outdated
| try { | ||
| body() | ||
| } catch(e) { | ||
| sleep(20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sleep only if it fails, then let's honor those steps that don't have a timeout issue
vars/withVaultToken.groovy
Outdated
| def token = getVaultSecret.getVaultToken(env.VAULT_ADDR, env.VAULT_ROLE_ID, env.VAULT_SECRET_ID) | ||
| dir(path) { | ||
| writeFile file: tokenFile, text: token | ||
| } | ||
| try { | ||
| body() | ||
| } catch (err) { | ||
| error "withVaultToken: error ${err}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrequired error, throw err is the one in charge.
vars/git.groovy
Outdated
| @@ -36,7 +36,11 @@ def call(params) { | |||
| def retryWithSleep(int i, body) { | |||
| retry(i) { | |||
| log(level: 'DEBUG', text: "Let's git (${i} tries).") | |||
| sleep(20) | |||
| body() | |||
| try { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a new step in the horizon 😄
sleepOnError(min: 0, max:30){
echo "I am a command"
}
def call(Map params = [:], Closure body) {
def min = params.containsKey('min') ? params.min : 0
def max = params.containsKey('max') ? params.max : 30
try{
body()
} catch (e){
sleep randomNumber(min: min, max: max)
throw e
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I actually was thinking to provide that step as a built-in step in the declarative pipeline:
retry(times: 3, sleep: 5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jenkinsci/workflow-basic-steps-plugin#97 is the one for that particular requirement :)
What does this PR do?
Try/Catch errors and retry with a sleep.
Why is it important?
It will speed up the CI builds as the sleep doesn't happen firstly but only if there are failures.
The sleep was in place to ensure DDOS attack is not detected when running a bunch of parallel stages to interact with our systems, such as docker.registry and vault.
Related issues
This could be implemented with the proposal in jenkinsci/workflow-basic-steps-plugin#97
How to test this
Tests
From 12 seconds average to 2 seconds
From 30 seconds average to 18 seconds
From 1min and 40 seconds average to 24 seconds